gdal2metadata.py script generates Federal Geographic Data Committee (FGDC) compliant metadata XML files from GDAL-supported rasters.
Overview
gdal2metadata.py extracts spatial information from a georeferenced raster and populates an FGDC metadata template, automating the creation of standards-compliant metadata documentation.
Usage
Path to input georeferenced raster file
Path to FGDC metadata XML template
Path to output populated metadata XML
Print detailed image information during processing
Workflow
Prepare FGDC template
Start with an FGDC metadata XML template containing your static metadata (title, abstract, contact information, etc.)
What Gets Populated
The script automatically extracts and populates:Spatial Information
- Bounding coordinates
- Coordinate system
- Projection parameters
- Datum and spheroid
Raster Properties
- Image dimensions
- Pixel resolution
- Number of bands
- Data type
Geotransform
- Upper-left coordinates
- Pixel spacing
- Rotation parameters
Temporal
- Current date/time stamp
- Processing date
Template Requirements
Your FGDC template XML must:- Conform to FGDC-STD-001-1998 (CSDGM - Content Standard for Digital Geospatial Metadata)
- Include placeholder elements for automatic population
- Contain complete static metadata (title, abstract, purpose, contact info, etc.)
Example Template Structure
Included Templates
The repository includes example templates:- USGS DEM Template
- ASU DTM Template
- NAC DTM Example
File:
USGS_DEM_template.tif.xmlDesigned for USGS Digital Elevation Models with standard USGS metadata sections.FGDC Metadata Standard
About FGDC CSDGM
The Federal Geographic Data Committee’s Content Standard for Digital Geospatial Metadata (FGDC-STD-001-1998) defines:Identification Information
Identification Information
- Citation (title, publication date, authors)
- Description (abstract, purpose)
- Time period of content
- Spatial domain (bounding coordinates)
- Keywords and themes
- Access and use constraints
Data Quality Information
Data Quality Information
- Positional accuracy
- Attribute accuracy
- Logical consistency
- Completeness
- Lineage (source data and processing steps)
Spatial Data Organization
Spatial Data Organization
- Raster vs. vector
- Resolution/cell size
- Number of bands/dimensions
Spatial Reference Information
Spatial Reference Information
- Horizontal coordinate system
- Projection parameters
- Geodetic model (datum, spheroid)
- Vertical coordinate system
Entity and Attribute Information
Entity and Attribute Information
- Attribute definitions
- Value domains and ranges
- Units of measure
Distribution Information
Distribution Information
- Distributor contact
- Distribution format
- Transfer options
Metadata Reference Information
Metadata Reference Information
- Metadata date
- Metadata contact
- Metadata standard name and version
Implementation Details
XML Processing
The script uses Python’s XML libraries in order of preference:- lxml.etree (preferred - most robust)
- xml.etree.cElementTree (Python 2.5+)
- xml.etree.ElementTree
- cElementTree
- elementtree.ElementTree
Recursive Element Search
The script uses recursive search to find and populate template elements:Requirements
Limitations and Notes
- FGDC version support: Currently only supports FGDC-STD-001-1998 (CSDGM)
- Manual editing required: Static content (abstract, purpose, lineage, etc.) must be in your template
- Validation recommended: Use FGDC metadata validation tools to verify output
Use Cases
Batch Processing
Automate metadata generation for large collections of rasters with similar characteristics
Data Publishing
Create compliant metadata for geospatial data portals and clearinghouses
Archive Preparation
Generate required metadata for long-term data archiving and preservation
Quality Assurance
Ensure spatial metadata consistency across multi-file datasets
Related Standards
While this tool generates FGDC metadata, be aware of related standards:- ISO 19115: International standard for geographic metadata
- ISO 19139: XML schema implementation of ISO 19115
- CSDGM → ISO conversion: Tools exist to convert FGDC to ISO format
Credits
Author: Trent Hare, USGS (thare@usgs.gov)Version: 0.2 (October 2011)
Based on: gdalinfo.py by Even Rouault and Frank Warmerdam
Released under MIT License. Use and modify freely for your metadata workflows.